{template '_header'}
 
<div class="page-heading"> 
	
	<span class='pull-right'>
		
		{ifp 'perm.user.add'}
                            <a class="btn btn-primary btn-sm" href="{php echo webUrl('perm/user/add')}">添加新操作员</a>
		{/if}

		<a class="btn btn-default  btn-sm" href="{php echo webUrl('perm/user')}">返回列表</a>


	</span>
	<h2><i class="fa fa-circle-o"></i>{if !empty($item['id'])}编辑{else}添加{/if}操作员 <small>{if !empty($item['id'])}修改【{$item['username']}】{/if}</small></h2>
</div>


    <form id="dataform" action="" method="post" class="form-horizontal form-validate" >
        <input type="hidden" name="id" value="{$item['id']}" />

                 <div class="form-group">
                     <label class="col-sm-1 control-label must">操作员用户名</label>
                    <div class="col-sm-11 col-xs-12">
                        {ife 'perm.user' $item}
                        <input type="text" name="username" class="form-control" value="{$item['username']}" {if !empty($item)}readonly{/if} data-rule-required=true autocomplete="off" />
	    <span class='help-block'>不能输入 微擎现有用户!  只能新增 权限才能生效. 新增的从这里可以修改</span>
                               {else}
                               <div class='form-control-static'>{$item['username']}</div>
                               {/if}
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-1 control-label must">操作员密码</label>
                    <div class="col-sm-11 col-xs-12">
                              {ife 'perm.user' $item}
                        <input type="password" name="password" class="form-control" value="" autocomplete="off" {if empty($item['password'])}data-rule-required='true' {/if}/>
                          {else}
                               <div class='form-control-static'>********</div>
                               {/if}
                    </div>
                </div>


                 <div class="form-group">
                    <label class="col-sm-1 control-label">所属角色</label>
                    <div class="col-sm-11 col-xs-12">
                         {ife 'perm.user' $item}
                        <input type='hidden' id='userid' name='roleid' value="{$role['id']}" />
                        <div class='input-group'>
                            <input type="text" name="user" maxlength="30" value="{$role['rolename']}" id="user" class="form-control" readonly />
                            <div class='input-group-btn'>
                                <button class="btn btn-default" type="button" onclick="popwin = $('#modal-module-menus1').modal();">选择角色</button>
                                <button class="btn btn-danger" type="button" onclick="$('#userid').val('');$('#user').val('');">清除选择</button>
                            </div>
                        </div>
						<span class='help-block'>如果您选择了角色，则此用户本身就继承了此角色的所有权限</span>
                        <div id="modal-module-menus1"  class="modal fade" tabindex="-1">
                            <div class="modal-dialog" style='width: 920px;'>
                                <div class="modal-content">
                                    <div class="modal-header"><button aria-hidden="true" data-dismiss="modal" class="close" type="button">×</button><h3>选择角色</h3></div>
                                    <div class="modal-body" >
                                        <div class="row">
                                            <div class="input-group">
                                                <input type="text" class="form-control" name="keyword" value="" id="search-kwd1" placeholder="请输入角色名称" />
                                                <span class='input-group-btn'><button type="button" class="btn btn-default" onclick="search_users();">搜索</button></span>
                                            </div>
                                        </div>
                                        <div id="module-menus1" style="padding-top:5px;"></div>
                                    </div>
                                    <div class="modal-footer"><a href="#" class="btn btn-default" data-dismiss="modal" aria-hidden="true">关闭</a></div>
                                </div>

                            </div>
                        </div>
                          {else}
                               <div class='form-control-static'>{$user['username']}</div>
                               {/if}
                    </div>
                </div>
                  <div class="form-group">
                    <label class="col-sm-2 control-label"> 姓名</label>
                    <div class="col-sm-9 col-xs-12">
                              {ife 'perm.user' $item}
                        <input type="text" name="realname" class="form-control" value="{$item['realname']}" />
                          {else}
                               <div class='form-control-static'>{$item['realname']}</div>
                               {/if}
                    </div>
                </div>
                  <div class="form-group">
                    <label class="col-sm-2 control-label">电话</label>
                    <div class="col-sm-9 col-xs-12">
                           {ife 'perm.user' $item}
                        <input type="text" name="mobile" class="form-control" value="{$item['mobile']}" />
                           {else}
                               <div class='form-control-static'>{$item['mobile']}</div>
                               {/if}
                    </div>
                </div>
            <!-- //修改，增加用户上架权限 -->
                 <div class="form-group">
                    <label class="col-sm-2 control-label">是否允许用户有上架功能</label>
                    <div class="col-sm-9 col-xs-12">
                             {ife 'perm.user' $item}
                        <label class='radio-inline'>
                            <input type='radio' name='st' value='1' {if $item['st']==1}checked{/if} /> 允许上架
                        </label>
                        <label class='radio-inline'>
                            <input type='radio' name='st' value='2' {if $item['st']==2}checked{/if} /> 禁止上架
                        </label>
                             {else}
                               <div class='form-control-static'>{if $item['st']==1}启用{else}禁用{/if}</div>
                               {/if}
                    </div>
                </div>
                <!-- //修改  增加用户导出订单数据 -->
                <div class="form-group">
                    <label class="col-sm-2 control-label">是否允许用户打印全部订单</label>
                    <div class="col-sm-9 col-xs-12">
                             {ife 'perm.user' $item}
                        <label class='radio-inline'>
                            <input type='radio' name='sq' value='1' {if $item['sq']==1}checked{/if} /> 允许打印全部订单
                        </label>
                        <label class='radio-inline'>
                            <input type='radio' name='sq' value='2' {if $item['sq']==2}checked{/if} /> 禁止打印全部订单
                        </label>
                             {else}
                               <div class='form-control-static'>{if $item['sq']==1}启用{else}禁用{/if}</div>
                               {/if}
                    </div>
                </div>


                <div class="form-group">
                    <label class="col-sm-2 control-label">状态</label>
                    <div class="col-sm-9 col-xs-12">
                             {ife 'perm.user' $item}
                        <label class='radio-inline'>
                            <input type='radio' name='status' value=1' {if $item['status']==1}checked{/if} /> 启用
                        </label>
                        <label class='radio-inline'>
                            <input type='radio' name='status' value=0' {if $item['status']==0}checked{/if} /> 禁用
                        </label>
                             {else}
                               <div class='form-control-static'>{if $item['status']==1}启用{else}禁用{/if}</div>
                               {/if}
                    </div>
                </div>
                 {ife 'perm.user' $item}
                 <div class="form-group">
                    <label class="col-sm-2 control-label"></label>
                    <div class="col-sm-9 col-xs-12">
                        <span class='form-control-static'>用户可以在此角色权限的基础上附加其他权限</span>
                    </div>
                </div>
                 {/if}

                {template 'perm/perms'}
                 {ife 'perm.user' $item}
                 {else}
                 <script language='javascript'>
                     $(function(){
                         $(':checkbox').attr('disabled',true);
                     })
                     </script>
                     {/if}
                <div class="form-group"></div>
                 <div class="form-group">
                    <label class="col-sm-2 control-label"></label>
                    <div class="col-sm-9 col-xs-12">
                         {ife 'perm.user' $item}
                            <input type="hidden" name="uid" value="{$item['uid']}" />
                        <input type="submit" value="提交" class="btn btn-primary" />

                        {/if}
                       <input type="button" name="back" onclick='history.back()' {ifp 'perm.user.add|perm.user.edit'}style='margin-left:10px;'{/if} value="返回列表" class="btn btn-default" />
                    </div>
                </div>

    </form>

<script language='javascript'>

    function search_users() {
        $("#module-menus1").html("正在搜索....")
        $.get('{php echo webUrl("perm/role/query")}', {
            keyword: $.trim($('#search-kwd1').val())
        }, function(dat){
            $('#module-menus1').html(dat);
        });
    }
    function select_role(o) {
        $("#userid").val(o.id);
        $("#user").val( o.rolename );
        var perms = o.perms2.split(',');


        $(':checkbox').removeAttr('disabled').removeAttr('checked').each(function(){

            var _this = $(this);
            var perm = '';
            if( _this.data('group') ){
                perm+=_this.data('group');
            }
            if( _this.data('parent') ){
                if (_this.data('parent') != 'text') {
                    perm += "." + _this.data('parent');
                }
            }
            if( _this.data('son') ){
                if (_this.data('son') != 'text') {
                    perm += "." + _this.data('son');
                }
            }
            if( _this.data('grandson') ){
                if (_this.data('grandson') != 'text') {
                    perm += "." + _this.data('grandson');
                }
            }
            if( $.arrayIndexOf(perms,perm)!=-1){
                $(this).attr('disabled',true).get(0).checked =true;
            }

        });
        $(".close").click();
    }
</script>
{template '_footer'}
 